package com.boot.controller;

import com.boot.entity.Dept;
import com.boot.service.DeptService;
import com.boot.utils.ResultVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@RequestMapping("dept")
@Controller
public class DeptController {
    @Resource
    private DeptService deptService;
    private ResultVO resultVO;

    @GetMapping
    @ResponseBody
    public ResultVO findDept(@RequestParam(defaultValue = "1")Integer pageNum, @RequestParam(defaultValue = "8")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Dept> list = deptService.findDept();
        PageInfo<Dept> pageInfo = new PageInfo(list);
        resultVO = ResultVO.success("查询成功",pageInfo);
        return resultVO;
    }

    @RequestMapping("find")
    @ResponseBody
    public Dept find(@RequestBody Dept dept){
        System.out.println("DeptController.find444"+dept);
        return dept;
    }


//    @RequestMapping("test")
//    public String test(){
//        System.out.println("DeptController.test");
//        return "index";
//    }


    // getmapping还是设置不了pn/ps
//    @GetMapping
//    public ResultVO findDept(@PathVariable Optional<Integer> pn, @PathVariable Optional<Integer> ps){
//        Integer pageNum = pn.orElse(1);
//        Integer pageSize = ps.orElse(5);
//        PageHelper.startPage(pageNum,pageSize);
//        List<Dept> list = deptService.findDept();
//        PageInfo<Dept> pageInfo = new PageInfo(list);
//        resultVO = ResultVO.success("查询成功",pageInfo);
//        return resultVO;
//    }

}
